snowsoft.gibay._LOG.info("Loading class, 'snowsoft.gibay.MyItems'");

/**
 * Calls no remote service
 * Handles MyItems Tab UI updates
 * @author digitalghost.liu@gmail.com 
 */
jsx3.lang.Class.defineClass("snowsoft.gibay.MyItems", null, [], function(MyItems) {
	
	//the model of current view	
	var _mode = 'RECENT';//two options:RECENT,WATCHLIST	
	
	//shortcut to package
	var gibay = snowsoft.gibay;

	MyItems.init = function(objEvent){
		var modelId = null;		

		if(_mode == 'RECENT'){
			modelId = 'MODEL_RecentItems';
		}else if(_mode == 'WATCHLIST'){
			modelId = 'MODEL_WatchList';
		}else{
			alert('Unknown MyItems mode');
			return;	
		}
		
		gibay.APP.getJSXByName("blkxItemList").setXMLId(modelId);
		gibay.APP.getJSXByName("blkxItemList").repaint();
		gibay._LOG.info("Initialize the MyItems for model "+modelId);
		//alert('paint myitems xml ok');
	};
	
	//method for handle the user change the myitem render mode
	MyItems.changeModel = function(objEvent){
		_mode = objEvent.cmd;
		gibay._LOG.info("MyItems render mode changed , mode "+_mode);
		MyItems.init();
	};

	//method for handle the user click on an item to view item's detail.
	MyItems.viewItem = function(itemID){
		var recItem = null;
		if(_mode == 'RECENT'){
			recItem = gibay.ModelManager.getRecentItems().getRecord(itemID);
		}else if(_mode == 'WATCHLIST'){
			recItem = gibay.ModelManager.getWatchList().getRecord(itemID);
		}else{
			alert('Unknown MyItems mode');
			return;	
		}
		if(recItem == null)
			return;
		jsx3.require("snowsoft.gibay.ViewItemDetail");
		snowsoft.gibay.publish({subject:snowsoft.gibay.Event.ON_VIEWITEM,target:this,itemRecord:recItem});
	};

	//method for handle the user click on delete link to delete an item for MODEL.
	MyItems.delItem = function(itemID){
		if(_mode == 'RECENT'){
			recItem = gibay.ModelManager.getRecentItems().deleteRecord(itemID,true);
		}else if(_mode == 'WATCHLIST'){
			recItem = gibay.ModelManager.getWatchList().deleteRecord(itemID,true);
		}else{
			alert('Unknown MyItems mode');
			return;	
		}	
		this.init();
	};
	
});


snowsoft.gibay.APP.subscribe(snowsoft.gibay.Event.ON_VIEWMYITEMS,snowsoft.gibay.MyItems.init);
snowsoft.gibay.APP.subscribe(snowsoft.gibay.Event.ON_VIEWMYITEMS_CHANGEMODEL,snowsoft.gibay.MyItems.changeModel);
